<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        let productId="";
        window.onload=function (){
            productId=getQuery("id");
            init();
        }
        async function init(){
            let productBean=await ajaxGet("/product/findById",{id:productId})
            let imgStr=`<img src="/html/img/${productBean.img}" width="250px" height="300px">`;
            getObject("imgDiv").innerHTML=imgStr;

            let infoStr=`<span>商品:${productBean.name}</span><br><br><br>
                        <span style="margin-top: 50px">单价:￥${productBean.money}</span><br><br><br>
                        <span style="margin-top: 50px">产地:${productBean.area}</span><br><br><br>
                        <span style="margin-top: 50px">生产日期:${productBean.date}</span><br><br><br>
                        <span style="margin-top: 50px">已售出${productBean.number}</span>`;
            getObject("infoDiv").innerHTML=infoStr;
        }
        async function back(){
            location.href="/html/index.html"
        }
        async function addProduct(){
            let userBean=await ajaxGet("/user/getLoginUser");
            let info=await ajaxGet("/shop/add",{userId:userBean.id,productId:productId})
            if (info=="ok"){
                location.href=`/html/custom/shop.html?userId=${userBean.id}`;
            }
        }
    </script>
</head>
<body>
    <div style="display: flex;margin-left: 100px;margin-top: 100px">
        <div id="imgDiv"></div>
        <div id="infoDiv" style="margin-left: 20px"></div>
    </div>
    <div style="margin-left: 100px;margin-top: 20px">
        <input type="button" value="购买" onclick="addProduct()">
        <input type="button" value="返回首页" style="margin-left: 50px" onclick="back()">
    </div>
</body>
</html>